#!/bin/sh
#(c) Copyright Barry Kauler 2012, license GPL3 (usr/share/doc/legal)
#a console font gets loaded in the initrd, or failing that in rc.country.
#i was also loading it in /usr/sbin/quicksetup if locale is changed.
#however, we have problems with it getting "dropped", which seems to happen when run X.
#so, i have created this script that will call whenever we exit from X, such as
#in xwin and in xorgwizard. thanks to L18L for investigating this.

#note, en locale will have empty /etc/fontmap...

if [ "$1" = "-s" ] ; then #menu to select a console font..
   ls /lib/consolefonts >/tmp/c_f_ 2>/dev/null
   max=$(cat /tmp/c_f_ | wc -l)
   x=1
   echo "Available console fonts:"
   while read cf ; do echo " $x $cf" ; x=$((x+1)) ; done < /tmp/c_f_
   echo -n "Type a number: " ; read nfont
   x=1
   while read cf ; do [ "$x" = "$nfont" ] && FONTMAP="$cf" ; x=$((x+1)) ; done < /tmp/c_f_
   rm -f /tmp/c_f_
   [ "$FONTMAP" = "" ] && exit
else
   [ ! -s /etc/fontmap ] && exit
   read FONTMAP < /etc/fontmap
fi

tty="$(tty 2>/dev/null)"
[ "$tty" = "" ] && tty="$(busybox tty 2>/dev/null)"
[ "$tty" = "" ] && tty='/dev/tty1'

FONTMAP=${FONTMAP%.gz}

case "$(file -b /lib/consolefonts/${FONTMAP}.gz)" in
	gz*|GZ*) zcat /lib/consolefonts/${FONTMAP}.gz | loadfont ;;
	*) setfont /lib/consolefonts/${FONTMAP}.gz -C $tty ;;
esac

### END ###
